﻿<%@ Page Language="C#" Theme="Admin"  MasterPageFile="~/admin/public/admin.master" %>
<%@ Import Namespace="Mani.Common" %>

<script runat="server">
	private void Page_Init()
	{
		UserRoles.DataSource = Roles.GetAllRoles();
		UserRoles.DataBind();
	}
	
	private void Page_PreRender()
	{
		MembershipUserCollection allUsers = Membership.GetAllUsers();
		MembershipUserCollection filteredUsers = new MembershipUserCollection();
		
		if (UserRoles.SelectedIndex > 0)
		{
			string[] usersInRole = Roles.GetUsersInRole(UserRoles.SelectedValue);
			foreach (MembershipUser user in allUsers)
			{
				foreach (string userInRole in usersInRole)
				{
					if (userInRole == user.UserName)
					{
						filteredUsers.Add(user);
						break; // Breaks out of the inner foreach loop to avoid unneeded checking.
					}
				}
			}
		}
		else
		{
			filteredUsers = allUsers;
		}
		Users.DataSource = filteredUsers;
		Users.DataBind();
	}
    protected string changeDate(DateTime date)
    {
        return date.ToJalali();
    }
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="content" Runat="Server">
<fieldset class="fieldset">
        <legend>کاربران بر اساس نقشها</legend>

<!-- #include file="_nav.aspx -->

<table STYLE="width:100%;">
<tr>
<td class="details" valign="top">

<!-- #include file="_nav3.aspx -->

فیلتر نقشها:

<asp:DropDownList style="font:11px tahoma;color:#555;" ID="UserRoles" runat="server" AppendDataBoundItems="true" AutoPostBack="true">
<asp:ListItem>همه موارد</asp:ListItem>
</asp:DropDownList>


<br /><br />
<div style="direction:ltr" >
<asp:GridView SkinID="GridWithFooter" runat="server" ID="Users" AutoGenerateColumns="false"
	  GridLines="none" >
<Columns>
	<asp:TemplateField>
		<HeaderTemplate>نام کاربری</HeaderTemplate>
		<ItemTemplate>
		<a href="edit_user.aspx?username=<%# Eval("UserName") %>"><%# Eval("UserName") %></a>
		</ItemTemplate>
	</asp:TemplateField>
	<asp:TemplateField HeaderText="تاریخ ایجاد">
              <ItemTemplate>
               <%#changeDate(Convert.ToDateTime(Eval("CreationDate")))%>
              </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="آخرین ورود">
              <ItemTemplate>
               <%#changeDate(Convert.ToDateTime(Eval("lastlogindate")))%>
              </ItemTemplate>
    </asp:TemplateField>
	<asp:BoundField DataField="isapproved" HeaderText="فعال" />
	<asp:BoundField DataField="isonline" HeaderText="Online" />
	<asp:BoundField DataField="islockedout" HeaderText="قفل" />
</Columns>
</asp:GridView>
</div>
</td></tr></table>
</fieldset>


</asp:Content>
